# Copyright (C) 2006  Apptility LLC  http://www.apptility.com
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA


class AjubySalesforceApi
  require 'integration/salesforce/ajuby_salesforce_pipe'
  
  API_STRING_CONST = "AjubySalesforceAPI"
  
  def initialize session
    @session = session
    @salesforcepipe = AjubySalesforcePipe.new()
    session['salesforce_login_context'] = @salesforcepipe.login_context
    #AjubyLogger.logInfo "salesforcepipe: #{session['salesforce_login_context']}"
  end


  def test_connection
    salesforcepipe.login
  end
      
  def get_modules
    begin
      salesforcepipe.get_modules_list
    rescue Exception => e
      raise AjubySalesforcePipe.build_err_trace("#{API_STRING_CONST}: get_modules call failed : " << e.message)
    end  
  end

  def get_module_records(module_name)
    begin
      salesforcepipe.get_module_records(100,module_name)
    rescue Exception => e
      raise AjubySalesforcePipe.build_err_trace("#{API_STRING_CONST}: get_module_records call failed : " << e.message)
    end  

  end
 
    
  def salesforce_login_context
    session['salesforce_login_context']
  end

  def salesforcepipe
    @salesforcepipe
  end
  
  def current_session
    @session
  end
  
end